package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.dto.CommunityRoomsDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CommunityRooms;
import com.ruoyi.system.service.ICommunityRoomsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * roomsController
 * 
 * @author yhb
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/system/rooms")
public class CommunityRoomsController extends BaseController
{
    @Autowired
    private ICommunityRoomsService communityRoomsService;

    /**
     * 查询rooms列表
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityRoomsDto communityRoomsDto)
    {
        startPage();
        List<CommunityRooms> list = communityRoomsService.selectCommunityRoomsList(communityRoomsDto);
        return getDataTable(list);
    }

//    /**
//     * 导出rooms列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:rooms:export')")
//    @Log(title = "rooms", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, CommunityRooms communityRooms)
//    {
//        List<CommunityRooms> list = communityRoomsService.selectCommunityRoomsList(communityRooms);
//        ExcelUtil<CommunityRooms> util = new ExcelUtil<CommunityRooms>(CommunityRooms.class);
//        util.exportExcel(response, list, "rooms数据");
//    }

    /**
     * 获取rooms详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityRoomsService.selectCommunityRoomsById(id));
    }

    /**
     * 新增rooms
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:add')")
    @Log(title = "rooms", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityRooms communityRooms)
    {
        return toAjax(communityRoomsService.insertCommunityRooms(communityRooms));
    }

    /**
     * 修改rooms
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:edit')")
    @Log(title = "rooms", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityRooms communityRooms)
    {
        return toAjax(communityRoomsService.updateCommunityRooms(communityRooms));
    }

    /**
     * 删除rooms
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:remove')")
    @Log(title = "rooms", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityRoomsService.deleteCommunityRoomsByIds(ids));
    }


    /**
     * 获取每个房间用途数量
     */
    @GetMapping("/purpose")
    public List<CommunityRooms> selectCommunityRoomsPurposeList(Long purposeId){
        return communityRoomsService.selectCommunityRoomsPurposeList(purposeId);
    }
}
